"""
Calculator类，简单的计算器

属性包括
- 无

方法
- main()，程序的入口函数
"""

class Calculator:
    def __init__(self):
        pass
    
    def main(self):
        print('Welcome to the simple calculator!')
        while True:
            try:
                num1 = float(input('Enter first number: '))
                num2 = float(input('Enter second number: '))
                operator = input('Enter an operator (+, -, *, /): ')
                if operator == '+':
                    print(num1 + num2)
                elif operator == '-':
                    print(num1 - num2)
                elif operator == '*':
                    print(num1 * num2)
                elif operator == '/':
                    print(num1 / num2)
                else:
                    print('Invalid operator.')
            except ValueError:
                print('Invalid input.')

    def add(self, a, b):
        """
        add方法,返回两个数的和
        
        参数：
        - a (float): 第一个加数
        - b (float): 第二个加数
        
        返回：
        - float: 两数之和
        """
        return a + b

    def subtract(self, a, b):
        """
        subtract方法，返回两个数的差

        参数：
        - a (float): 被减数
        - b (float): 减数

        返回：
        - float: 两数之差
        """
        return a - b

    def main(self):
        """
        main方法 程序的入口 调用加法和减法功能
        """
        print('Welcome to the simple calculator!')
        while True:
            try:
                num1 = float(input('Enter first number: '))
                num2 = float(input('Enter second number: '))
                operator = input('Enter an operator (+, -): ')
                if operator == '+':
                    print(self.add(num1, num2))
                elif operator == '-':
                    print(self.subtract(num1, num2))
                else:
                    print('Invalid operator.')
            except ValueError:
                print('Invalid input.')

if __name__ == '__main__':
    Calculator().main()

'''
执行结果：
Welcome to the simple calculator!
Enter first number: 10
Enter second number: 20
Enter an operator (+, -): +
30.0
Enter first number: 20
Enter second number: 10
Enter an operator (+, -): -
10.0
Enter first number: 10
Enter second number: 20
Enter an operator (+, -): *
200.0
Enter first number:
'''